tongfusoft.myDoc = function() {
}

tongfusoft.myDoc.prototype = {

	docList : function(pageIndex,pageSize,query,url) {
	
		
		common.post(url,{"pageIndex":pageIndex,"pageSize":pageSize,"query":query},function(data){
			
			var docListHtml="<tr><td>"
			$.each(data.list,function(index,item){
				
	
				docListHtml=docListHtml+'<div class="media-box">';
				docListHtml=docListHtml+'<a href="#" class="pull-left">';
				docListHtml=docListHtml+'<img src="'+common.getContextPath('img/dc/'+item.docIcon)+'" alt="" class="media-box-object img-responsive img-rounded thumb64">';
				docListHtml=docListHtml+'</a>';
				docListHtml=docListHtml+'<div class="media-box-body">';
				
				//操作按钮
				docListHtml=docListHtml+'<div class="pull-right">';
			
				docListHtml=docListHtml+'<button type="button" docname="'+item.docName+'"  class="btn btn-sm btn-default  icon-list detailBtn" ></button>'
				if(item.isWrite=='1'){
					docListHtml=docListHtml+'<button type="button" docname="'+item.docName+'"  class="btn btn-sm btn-default fa fa-edit editBtn"></button>';
				}
				if(item.isDelete=='1'){
					docListHtml=docListHtml+'<button type="button" docname="'+item.docName+'"  class="btn btn-sm btn-default fa fa-trash deleteBtn"></button>';
				}
					
				docListHtml=docListHtml+'</div>';
				
				
				docListHtml=docListHtml+'<h4 class="media-box-heading">'+item.docTitle+'</h4>';
				docListHtml=docListHtml+'<small title="'+item.docSummary+'" class="text-muted">'+item.docSummary.substr(0,50)+"....." +'</small>';
				docListHtml=docListHtml+'<p>';
				
				docListHtml=docListHtml+'<em class="fa fa-user mr-sm"> </em><span class="mr">'+item.docAuthor+'</span><em class="fa fa-building mr-sm"> </em><span>'+item.lastUpdDate+'</span>';
				docListHtml=docListHtml+'<span class="mr"></span><a href="'+common.getContextPath('download/'+item.docName)+'" target="_blank" ><em class="fa fa-download mr"></em></a>';
				docListHtml=docListHtml+'</p>';
				docListHtml=docListHtml+'</div>';
				docListHtml=docListHtml+' </div>';
				
				
			});
			
			docListHtml=docListHtml+'</td></tr>';
			$("#docListTable").html(docListHtml);
			new tongfusoft.myDoc().pageing(data);
			
			new tongfusoft.myDoc().editBtn();
			new tongfusoft.myDoc().detailBtn();
			new tongfusoft.myDoc().deleteBtn();
			
		});
	},
	//新增页面
	checkInBtn:function(){
		$(".checkInBtn").unbind('click');
		$(".checkInBtn").click(function(){
			
			window.location.href=common.getContextPath('docCheckIn');
			
		});
		
	},
	//分页
	pageing:function(data){
		
		$('#docListPage').jqPaginator({
		    totalPages: data.pages==0?1:data.pages,
		    visiblePages: 5,
		    currentPage: 1,
		    pageSize:data.pageSize,
		    first: '',
	        prev: '<li class="prev"><a href="javascript:;">上一页</a></li>',
	        next: '<li class="next"><a href="javascript:;">下一页</a></li>',
	        last: '',
	        page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
		    onPageChange: function (num, type) {
		    	if(type=='change')
		    		new tongfusoft.myDoc().docList(num,data.pageSize,$("#queryText").val(),$("#queryUrl").val());
		    }
		});
	},
	//编辑
	editBtn:function(){
		$(".editBtn").unbind('click');
		
		$(".editBtn").click(function(){
			
			window.location.href=common.getContextPath('docUpdate/'+$("#returnPage").val()+'/'+$(this).attr("docName"));
			
		});
	},
	//详情
	detailBtn:function(page){
		
		
		$(".detailBtn").unbind('click');

		$(".detailBtn").click(function(){
			
			window.location.href=common.getContextPath('docView/'+$("#returnPage").val()+'/'+$(this).attr("docName"));
			
		});
	},
	//查询
	searchBtn:function(url){
		
		$("#searchBtn").click(function(){
			$("#queryText").val(JSON.stringify({"fastText":$("#searchText").val()}));
			new tongfusoft.myDoc().docList(1,10,$("#queryText").val(),url);
			
		});
		
	},
	//删除
	deleteBtn:function(){
		$(".deleteBtn").unbind('click');

		$(".deleteBtn").click(function(){
			
			var url='docDel/'+$(this).attr("docname")

		swal({
			title : "是否确认删除?",
			text : "",
			type : "warning",
			showCancelButton : true,
			confirmButtonColor : "#DD6B55",
			confirmButtonText : "删除",
			cancelButtonText : "取消",
			closeOnConfirm : true
		}, function() {
			common.ajaxSubmitOnSuccess({},url , function(data) {

				if (data.state == 'success') {

					window.location.reload();
				}else{
					if(data.code=='delete_power_error'){
						
						toastr["error"]('操作权限不足');
						
					}
				}

			}, "del")
		});

		});
		
	}

}



